



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class GroupsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public GroupsDB()
        {
        }

        public GroupsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Groups> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Groups> lstRet = new List<Groups>();

            string strQuery = " select " + strTop  + " * from dbo.[Groups]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Groups obj = new Groups();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["GroupNameAR"] != DBNull.Value)
                    {
                        obj.GroupNameAR = (System.String)dr["GroupNameAR"];
                    }
                    else
                    {
                        obj.GroupNameAR = "";
                    } 
 if (dr["GroupNameEN"] != DBNull.Value)
                    {
                        obj.GroupNameEN = (System.String)dr["GroupNameEN"];
                    }
                    else
                    {
                        obj.GroupNameEN = "";
                    } 
 if (dr["SystemGroup"] != DBNull.Value)
                    {
                        obj.SystemGroup = (System.Boolean)dr["SystemGroup"];
                    }
                    else
                    {
                        obj.SystemGroup = false;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Groups> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Groups> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Groups obj)
        {
            
            

                    DbParameter prmGroupNameAR = con.createParameter();
                    prmGroupNameAR.ParameterName = "@GroupNameAR";
                    prmGroupNameAR.DbType =DbType.String;
                    if (obj.GroupNameAR == null)
                    {
                        prmGroupNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGroupNameAR.Value = obj.GroupNameAR;
                    }
                

                    


                    DbParameter prmGroupNameEN = con.createParameter();
                    prmGroupNameEN.ParameterName = "@GroupNameEN";
                    prmGroupNameEN.DbType =DbType.String;
                    if (obj.GroupNameEN == null)
                    {
                        prmGroupNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGroupNameEN.Value = obj.GroupNameEN;
                    }
                

                    


                    DbParameter prmSystemGroup = con.createParameter();
                    prmSystemGroup.ParameterName = "@SystemGroup";
                    prmSystemGroup.DbType =DbType.Boolean;
                    if (obj.SystemGroup == null)
                    {
                        prmSystemGroup.Value = DBNull.Value;
                    }
                    else
                    {
                        prmSystemGroup.Value = obj.SystemGroup;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Groups] ([GroupNameAR],[GroupNameEN],[SystemGroup]) VALUES (@GroupNameAR,@GroupNameEN,@SystemGroup) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmGroupNameAR,prmGroupNameEN,prmSystemGroup);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Groups obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Groups obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmGroupNameAR = con.createParameter();
                    prmGroupNameAR.ParameterName = "@GroupNameAR";
                    prmGroupNameAR.DbType =DbType.String;
                    if (obj.GroupNameAR == null)
                    {
                        prmGroupNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGroupNameAR.Value = obj.GroupNameAR;
                    }
                

                    


                    DbParameter prmGroupNameEN = con.createParameter();
                    prmGroupNameEN.ParameterName = "@GroupNameEN";
                    prmGroupNameEN.DbType =DbType.String;
                    if (obj.GroupNameEN == null)
                    {
                        prmGroupNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmGroupNameEN.Value = obj.GroupNameEN;
                    }
                

                    


                    DbParameter prmSystemGroup = con.createParameter();
                    prmSystemGroup.ParameterName = "@SystemGroup";
                    prmSystemGroup.DbType =DbType.Boolean;
                    if (obj.SystemGroup == null)
                    {
                        prmSystemGroup.Value = DBNull.Value;
                    }
                    else
                    {
                        prmSystemGroup.Value = obj.SystemGroup;
                    }
                

                    


           



            string strQuery = " update dbo.[Groups] set [GroupNameAR]=@GroupNameAR,[GroupNameEN]=@GroupNameEN,[SystemGroup]=@SystemGroup where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmGroupNameAR,prmGroupNameEN,prmSystemGroup);

            

        }


        public void Update(Groups obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Groups obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Groups]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Groups obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Groups> getGroupsByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Groups> lstRet = new List<Groups>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Groups> getGroupsByID(System.Int64 ID)
                    {
                        List<Groups> lstRet = new List<Groups>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getGroupsByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Groups> getGroupsByGroupNameAR(ClassDataHandler con,System.String GroupNameAR)
                    {
                        List<Groups> lstRet = new List<Groups>();


                        DbParameter prmGroupNameAR = con.createParameter();
                        prmGroupNameAR.ParameterName = "@GroupNameAR";
                        prmGroupNameAR.DbType = DbType.String;
                        if (GroupNameAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmGroupNameAR.Value = GroupNameAR;
                        }


                        lstRet = Select(con, "" , " where [GroupNameAR]=@GroupNameAR ", prmGroupNameAR);



                        return lstRet;

                    }


                    public List<Groups> getGroupsByGroupNameAR(System.String GroupNameAR)
                    {
                        List<Groups> lstRet = new List<Groups>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getGroupsByGroupNameAR(con, GroupNameAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Groups> getGroupsByGroupNameEN(ClassDataHandler con,System.String GroupNameEN)
                    {
                        List<Groups> lstRet = new List<Groups>();


                        DbParameter prmGroupNameEN = con.createParameter();
                        prmGroupNameEN.ParameterName = "@GroupNameEN";
                        prmGroupNameEN.DbType = DbType.String;
                        if (GroupNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmGroupNameEN.Value = GroupNameEN;
                        }


                        lstRet = Select(con, "" , " where [GroupNameEN]=@GroupNameEN ", prmGroupNameEN);



                        return lstRet;

                    }


                    public List<Groups> getGroupsByGroupNameEN(System.String GroupNameEN)
                    {
                        List<Groups> lstRet = new List<Groups>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getGroupsByGroupNameEN(con, GroupNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Groups> getGroupsBySystemGroup(ClassDataHandler con,System.Boolean SystemGroup)
                    {
                        List<Groups> lstRet = new List<Groups>();


                        DbParameter prmSystemGroup = con.createParameter();
                        prmSystemGroup.ParameterName = "@SystemGroup";
                        prmSystemGroup.DbType = DbType.Boolean;
                        if (SystemGroup == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmSystemGroup.Value = SystemGroup;
                        }


                        lstRet = Select(con, "" , " where [SystemGroup]=@SystemGroup ", prmSystemGroup);



                        return lstRet;

                    }


                    public List<Groups> getGroupsBySystemGroup(System.Boolean SystemGroup)
                    {
                        List<Groups> lstRet = new List<Groups>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getGroupsBySystemGroup(con, SystemGroup);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Groups> Search(ClassDataHandler con, Groups obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.GroupNameAR != "")
                    {
                        DbParameter prmGroupNameAR = con.createParameter();
                        prmGroupNameAR.ParameterName = "@GroupNameAR";
                        prmGroupNameAR.DbType =DbType.String;
                        if (obj.GroupNameAR == null)
                        {
                            prmGroupNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGroupNameAR.Value = obj.GroupNameAR;
                        }
                        strWhere += " [GroupNameAR]=@GroupNameAR AND ";
                        lstParameters.Add(prmGroupNameAR);
                     }



                    

                    if (obj.GroupNameEN != "")
                    {
                        DbParameter prmGroupNameEN = con.createParameter();
                        prmGroupNameEN.ParameterName = "@GroupNameEN";
                        prmGroupNameEN.DbType =DbType.String;
                        if (obj.GroupNameEN == null)
                        {
                            prmGroupNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGroupNameEN.Value = obj.GroupNameEN;
                        }
                        strWhere += " [GroupNameEN]=@GroupNameEN AND ";
                        lstParameters.Add(prmGroupNameEN);
                     }



                    

                    if (obj.SystemGroup != false)
                    {
                        DbParameter prmSystemGroup = con.createParameter();
                        prmSystemGroup.ParameterName = "@SystemGroup";
                        prmSystemGroup.DbType =DbType.Boolean;
                        if (obj.SystemGroup == null)
                        {
                            prmSystemGroup.Value = DBNull.Value;
                        }
                        else
                        {
                            prmSystemGroup.Value = obj.SystemGroup;
                        }
                        strWhere += " [SystemGroup]=@SystemGroup AND ";
                        lstParameters.Add(prmSystemGroup);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Groups> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Groups> Search(Groups obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Groups> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Groups> SearchOrLike(ClassDataHandler con, Groups obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.GroupNameAR != "")
                    {
                        DbParameter prmGroupNameAR = con.createParameter();
                        prmGroupNameAR.ParameterName = "@GroupNameAR";
                        prmGroupNameAR.DbType =DbType.String;
                        if (obj.GroupNameAR == null)
                        {
                            prmGroupNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGroupNameAR.Value = obj.GroupNameAR;
                        }
                        strWhere += " [GroupNameAR] LIKE @GroupNameAR OR ";
                        lstParameters.Add(prmGroupNameAR);
                     }



                    

                    if (obj.GroupNameEN != "")
                    {
                        DbParameter prmGroupNameEN = con.createParameter();
                        prmGroupNameEN.ParameterName = "@GroupNameEN";
                        prmGroupNameEN.DbType =DbType.String;
                        if (obj.GroupNameEN == null)
                        {
                            prmGroupNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmGroupNameEN.Value = obj.GroupNameEN;
                        }
                        strWhere += " [GroupNameEN] LIKE @GroupNameEN OR ";
                        lstParameters.Add(prmGroupNameEN);
                     }



                    

                    if (obj.SystemGroup != false)
                    {
                        DbParameter prmSystemGroup = con.createParameter();
                        prmSystemGroup.ParameterName = "@SystemGroup";
                        prmSystemGroup.DbType =DbType.Boolean;
                        if (obj.SystemGroup == null)
                        {
                            prmSystemGroup.Value = DBNull.Value;
                        }
                        else
                        {
                            prmSystemGroup.Value = obj.SystemGroup;
                        }
                        strWhere += " [SystemGroup]=@SystemGroup OR ";
                        lstParameters.Add(prmSystemGroup);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Groups> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Groups> SearchOrLike(Groups obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Groups> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            